/*
 * Copyright 2004-2011 Paolo Conte
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jellylab.ojoverse;

import java.util.logging.Level;

public class Message {

  public static int OK = 0;
  public static int CONFIG = 1;
  public static int INFO = 2;
  public static int WARNING = 4;
  public static int ERROR = 8;
  public static int FATAL = 16;
  
  protected String name = "";
  protected int type = 0;
  protected Object message = null;

  public Message() {
    this("empty message", OK, "A default message useful to avoid null comparison");
  }
  
  public Message(String name, int type) {
    this(name, type, null);
  }
  
  public Message(String name, Object message) {
    this(name, CONFIG, message);
  }

  public Message(String name, int type, Object message) {
    this.name = name;
    this.type = type;
    this.message = message;
  }

  public boolean isOK() {
    return type == OK;
  }
  
  public boolean isNearOK() {
    return (type == OK) || (type == CONFIG) || (type == INFO);
  }
  
  public boolean isKO() {
    return type > INFO;
  }
  
  public Object getName() {
    return name;
  }

  public Object getType() {
    return type;
  }

  public Object getMessage() {
    return message;
  }

  public void setMessage(Object message) {
    this.message = message;
  }

  public String toString() {
    return "Message[" + type + "]: " + name + " = " + message.toString();
  }
}
